package cn.dansj.common.utils.enums;

public enum ResponseCode {
    Success(200, "请求成功", 200),
    Error(500, "请求失败", 500),
    TooMany(551, "访问过于频繁,当前等级: %s级 ,QPS = %s", 500),
    UpperLimit(552, "当日已达到上限,当前等级: %s级, 每天最多调用%s次", 500),
    InterceptDDL(553, "接口存在异常,请求被拦截,请联系我们", 500),//存在DDL语句
    InterceptSQLParseError(555, "接口存在异常,请求被拦截,请联系我们", 500),//sql解析错误
    ResultNotUnique(556, "接口存在异常,请求被拦截,请联系我们", 500),//sql返回的结果不唯一
    SqlRunFailed(557, "接口存在异常,请求被拦截,请联系我们", 500),//sql执行失败
    UpperMaxPageSize(558, "超过最大页数", 500),
    TypeNotExist(559, "请求类型错误", 500),
    RunTimeError(560, "请求失败", 500),//运行时异常
    ClientAbortDownload(561, "客户端取消下载", 500),
    FileDownloadException(562, "文件下载异常", 500),
    ProjectTokenNotSupport(563, "不支持免密调试,请自行使用token参数调试", 500),
    ParameterNotPresent(400, "%s类型的请求参数[ %s ]不存在", 400),
    NoAuthorize(401, "接口无访问权限", 401),
    AuthenticationFailed(451, "验证失败", 401),
    TokenError(452, "token验证失败,请输入正确的token", 401),
    AuthenticationSuccess(200, "验证通过", 200),
    NotExist(404, "接口不存在", 404);
    private final int statusCode;
    private final String error;
    private final int responseCode;

    ResponseCode(int statusCode, String error, int responseCode) {
        this.statusCode = statusCode;
        this.error = error;
        this.responseCode = responseCode;
    }

    public int getStatusCode() {
        return statusCode;
    }

    public int getResponseCode() {
        return responseCode;
    }

    public static ResponseCode getResponseCode(int statusCode) {
        for (ResponseCode response : values()) {
            if (response.statusCode == statusCode) {
                return response;
            }
        }
        throw new IllegalArgumentException("无效的状态码:" + statusCode);
    }

    public String getError() {
        return error;
    }
}